const http = require('http')
const { URL } = require('url')

const server = http.createServer((request, response) => {
  const urlObj = new URL(request.url, 'http://localhost:8080')
  console.log(urlObj);

  switch (urlObj.pathname) {
    case '/getUserInfo':
      const data = {
        name: '张三',
        id: '1',
        sex: '男',
      }
      response.end(`${urlObj.searchParams.get('callback')}(${JSON.stringify(data)})`)
      break
    default:
      response.end('404.')
      break
  }
})

server.listen(8080, () => {
  console.log('localhost:8080');
})
